package net.togogo;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloHttpServlet extends HttpServlet {

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        //重写了Servlet的init方法后一定要记得调用父类的init方法
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        System.out.println("HelloHttpServlet的GET方法被调用");
    }

    @Override
    protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        //super.doPost(httpServletRequest, httpServletResponse);
        System.out.println("HelloHttpServlet的POST方法被调用");
        ServletConfig servletConfig = getServletConfig();
        System.out.println("获取servlet程序的别名--->" + servletConfig.getServletName());
        System.out.println("获取初始化参数:username-->" + servletConfig.getInitParameter("username"));
        System.out.println("获取初始化参数:password-->" + servletConfig.getInitParameter("password"));
        System.out.println("获取ServletContext对象-->" + servletConfig.getServletContext());
    }
}
